package com.service.business.trading.task;


//import com.service.business.rabbitmq.binding.MatchSendHandler;
import com.service.business.trading.service.TradingSpotOrderService;
import com.service.dao.model.TradingSpotOrder;
import com.service.match.common.enums.TradingSpotEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.Date;
import java.util.List;


@Slf4j
@Component
public class SpotOrderTask {

//    @Autowired
//    private MatchSendHandler matchSendHandler;
    @Autowired
    private TradingSpotOrderService spotOrderService;

//    @Scheduled(cron = "0/10 * * * * ?")
    public void doSchedule() {
        log.info("not send mq spot order -定时任务");
        Date queryTime = DateUtils.addSeconds(new Date(), -2);
        List<TradingSpotOrder> spotOrderList = spotOrderService.listByStatusAndTime(TradingSpotEnum.Status.CREATED, queryTime);
        if (ObjectUtils.isEmpty(spotOrderList)) {
            log.info("暂无未发送至撮合引擎的交易订单");
            return;
        }

        spotOrderList.parallelStream().forEach(item -> {
            log.info("交易订单<id:{}>发送至撮合引擎", item.getId());
//            matchSendHandler.sendNewOrder(spotOrderService.buildMsgVo(item, item.getTradeType()));
        });

    }


}
